<?php
namespace app\home\controller;
header("Content-type: text/html; charset=utf-8");
use think\Controller;
use think\Db;
use think\Cache;
use think\Validate;
use app\admin\model\User;
class Information extends Controller {
    public function notice(){
        $status0['status']=0;
        $status1['status']=1;
        //$_POST['information_id'] = 40;
        $information = Db::name('information');
        $res = $information->where('information_id='.$_POST['information_id'].' AND information_status=0')->select();
        if(empty($res)){
            return json($status1);
            //echo '<script>alert(\'你没有收到消息！\');window.location.href=\''.U('Information/already_send_information').'\';</script>';
        }else if(!empty($res)){
            return json($status0);
        }
    }

    public function information(){
        $status1['status']=1;
        $information = Db::name('information');
        $res = $information
            ->where('information_id='.$_POST['information_id'])
            ->order('id desc')
            ->select();
        if(empty($res)){
            return json($status1);
            //echo '<script>alert(\'你没有收到消息！\');window.location.href=\''.U('Information/already_send_information').'\';</script>';
        }else if(!empty($res)){
            return json($res);
        }
    }



    public function see_all_information(){
        $status0['status']=0;
        $status1['status']=1;
        $information = Db::name('information');
        $data['information_status'] = 1;
        $see_all=$information->where('information_id="'.$_POST['information_id'].'" AND information_status=0')->select();
        foreach($see_all as $key => $val) {
            $res = $information->where('id='.$val['id'])->update($data);
        }
        if($res){
            return json($status0);
            //echo '<script>alert(\'查看所有消息成功！\');window.location.href=\''.U('Information/already_send_information').'\';</script>';
        }else{
            return json($status1);
           // echo '<script>alert(\'查看所有消息失败！\');history.back(-1);</script>';
        }
    }
}